/**
 * 
 */
package verda.kvantumo.Itala_Esperanta_Vortaro;

import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.AdapterView.OnItemClickListener;

/**
 * @author kvantumo
 *
 */
public class GramatikoListo extends Activity {
	
	List<String> gramatikaListo = new ArrayList<String>();
	String LISTO_DOSIERO = "gramatiko_titoloj_listo";
	static final int[] rawListo = {R.raw.gramatiko_00, 
			R.raw.gramatiko_01,
			R.raw.gramatiko_02,
			R.raw.gramatiko_03,
			R.raw.gramatiko_04,
			R.raw.gramatiko_05,
			R.raw.gramatiko_06,
			R.raw.gramatiko_07,
			R.raw.gramatiko_08,
			R.raw.gramatiko_09,
			R.raw.gramatiko_10,
			R.raw.gramatiko_11,
			R.raw.gramatiko_12,
			R.raw.gramatiko_13};
	
	@Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.gramatico_listo);

        sxargxasGramatikanListon();
        
        ListView listo = (ListView) findViewById(R.id.listView_gramatiko);
        listo.setAdapter(new ArrayAdapter<String>(listo.getContext(),
                android.R.layout.simple_list_item_1, gramatikaListo));
        listo.setOnItemClickListener(new OnItemClickListener(){
        	public void onItemClick(AdapterView arg0, View arg1, int position, long arg3) {
        		Intent i = new Intent("verda.kvantumo.Itala_Esperanta_Vortaro.GRAMATIKERO");
        	    Bundle extras = new Bundle();
        	    extras.putInt("gramatikero", rawListo[position]);
        	    extras.putString("nomo", gramatikaListo.get(position));
        	    i.putExtras(extras);
        	    startActivity(i);
        	}
        });
	}
	
	public void sxargxasGramatikanListon(){
		   try
		   {
			   BufferedReader in = new BufferedReader(new InputStreamReader(getResources().openRawResource(R.raw.gramatiko_titoloj_listo)));
			   String temp;
			   String[] q;
			   while((temp = in.readLine()) != null){
				   gramatikaListo.add(temp);
			   }
		   }
		   catch (FileNotFoundException e) {
			   e.printStackTrace();
		   }
		   catch (IOException ioe) {
			   ioe.printStackTrace();
		   }
	   }
}
